set pStartH to the locH of sprite the spriteNum of me
set pNewTriggerResetPosition to pTriggerResetPosition + -random(50)
set the locH of sprite the spriteNum of me to the locH of sprite the spriteNum of me + random(8)
end
on enterFrame me
if pWhichDirection = #up then
if the locV of sprite the spriteNum of me > pNewTriggerResetPosition then
set pNewTriggerResetPosition to pTriggerResetPosition + -random(50)
set the locV of sprite the spriteNum of me to the locV of sprite the spriteNum of me - pSpeed
set testForOffset to random(pOffsetFrequency)
if testForOffset = 2 then
set hOffset to -1
else
if testForOffset = 1 then
set hOffset to 1
else
set hOffset to 0
end if
end if
set the locH of sprite the spriteNum of me to the locH of sprite the spriteNum of me + hOffset
else
set the locV of sprite the spriteNum of me to pResetSpritePosition + random(8)
end if
if (the locH of sprite the spriteNum of me > 151) or (the locH of sprite the spriteNum of me < -8) then
set the locV of sprite the spriteNum of me to pResetSpritePosition + random(8)
set the locH of sprite the spriteNum of me to pStartH
end if
end if
if pWhichDirection = #down then
if the locV of sprite the spriteNum of me < pTriggerResetPosition then
set the locV of sprite the spriteNum of me to the locV of sprite the spriteNum of me + pSpeed
else
set the locV of sprite the spriteNum of me to pResetSpritePosition
end if
end if
if pWhichDirection = #left then
if the locH of sprite the spriteNum of me > pTriggerResetPosition then
set the locH of sprite the spriteNum of me to the locH of sprite the spriteNum of me - pSpeed
else
set the locH of sprite the spriteNum of me to pResetSpritePosition
end if
end if
if pWhichDirection = #right then
if the locH of sprite the spriteNum of me < pTriggerResetPosition then
set the locH of sprite the spriteNum of me to the locH of sprite the spriteNum of me + pSpeed
else
set the locH of sprite the spriteNum of me to pResetSpritePosition
end if
end if
end
on getPropertyDescriptionList
set propertyDescriptionList to [#pWhichDirection: [#comment: "Which direction:", #format: #symbol, #range: [#up, #down, #left, #right], #default: #up], #pSpeed: [#comment: "What speed (#pixels per frame):", #format: #integer, #default: 1], #pTriggerResetPosition: [#comment: "Postion that triggers reset:", #format: #integer, #default: 0], #pResetSpritePosition: [#comment: "Position to reset to:", #format: #integer, #default: 0], #pOffsetFrequency: [#comment: "Offset frequency (bigger number is less frequent)", #format: #integer, #default: 4]]
return propertyDescriptionList
end
on getBehaviorDescription
return "This behavior will move a sprite automatically up, down, left, or right at 1 or more pixels per frame, and also loop the motion. You need to set the position the sprite will get to before resetting itself and the position it should reset itself to."